package com.aliyun.dao;


import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.aliyun.bean.QueryPara;

@Component("yumingDao")
@Transactional
public class YuMingDao extends CommonDao{
	
	public int insertYuMing(Map<String, String> map)throws SQLException{
		//判断该用户有几个地区
		List<Map<String,Object>> list = this.getSqlSession().selectList("com.aliyun.dao.UserMapper.getUserArea", map);
		if(list!=null && list.size()>0){
			for(Map<String,Object> mp : list){
				map.put("areacode", mp.get("areacode")+"");
				this.getSqlSession().insert("com.aliyun.dao.YuMingMapper.insertYuMing",map);
			}
		}
		return 1;
	}
	public int insertYuMingList(List<Map<String,String>> list)throws SQLException{
		int i = 0;
		List<Map<String,Object>> listArea = this.getSqlSession().selectList("com.aliyun.dao.UserMapper.getUserArea", list.get(0));
		if(listArea!=null && listArea.size()>0){
			for(Map<String,Object> mp : listArea){
				for(Map<String,String> map : list){
					map.put("areacode", mp.get("areacode")+"");
					map.put("username", mp.get("username")+"");
					i+=this.getSqlSession().insert("com.aliyun.dao.YuMingMapper.insertYuMing",map);
				}
			}
		}
		return i;
	}
	public int deleteYuMing(List<Map<String,String>> list)throws SQLException{
		int i = 0;
				for(Map<String,String> map : list){
					i+=this.getSqlSession().delete("com.aliyun.dao.YuMingMapper.deleteYuMing",map);
				}
		return i;
	}
	public int updateYuMingStatus(Map<String, String> map)throws SQLException{
		return this.getSqlSession().insert("com.aliyun.dao.YuMingMapper.updateYuMingStatus",map);
	}
	public List<Map<String, Object>> getYuMingItem(QueryPara qp)throws SQLException{
        return this.getSqlSession().selectList("com.aliyun.dao.YuMingMapper.getYuMingItem",qp);
    }
	public List<Map<String, Object>> getYuMingList(Map<String,String> map)throws SQLException{
        return this.getSqlSession().selectList("com.aliyun.dao.YuMingMapper.getYuMingList",map);
    }
	public List<Map<String, Object>> getYuMingTimeList(Map<String,String> map)throws SQLException{
        return this.getSqlSession().selectList("com.aliyun.dao.YuMingMapper.getYuMingTimeList",map);
    }
	public List<Map<String, Object>> getYuMingTime()throws SQLException{
        return this.getSqlSession().selectList("com.aliyun.dao.YuMingMapper.getYuMingTime");
    }
	public Map<String, Object> getYuMingItemOne()throws SQLException{
        return this.getSqlSession().selectOne("com.aliyun.dao.YuMingMapper.getYuMingItemOne");
    }
}
